package com.geek.concurrence4work;

import java.util.concurrent.Semaphore;

/**
 * @Author: lishuangqiang
 * @Date: 2021/11/28
 * @Description:
 */

public class SemaphoreMethod {

    protected static class MyThread extends Thread {
        private Semaphore semaphore;
        private volatile Long res = null;

        public MyThread(Semaphore semaphore) {
            this.semaphore = semaphore;
        }

        @Override
        public void run() {
            res = Homework03.sum3();
            semaphore.release();
        }


        public Long getRes() throws InterruptedException {
            semaphore.acquire();
            return res;
        }
    }


    public static void main(String[] args) throws InterruptedException {
        Semaphore semaphore = new Semaphore(1);
        semaphore.acquire();
        MyThread myThread = new MyThread(semaphore);
        myThread.start();
        System.out.println(myThread.getRes());
    }
}
